package com.xinxin.leetcode.problem689;

/**
 * @author ShiXinXin
 * @date 2020-02-23 21:35
 */
public class Solution {
    public int repeatedStringMatch(String A, String B) {
        StringBuilder builder = new StringBuilder(A);
        while (builder.length() < B.length()) {
            builder.append(A);
        }
        if (builder.lastIndexOf(B) != -1) {
            return builder.length() / A.length();
        } else {
            builder.append(A);
            if (builder.lastIndexOf(B) != -1) {
                return builder.length() / A.length();
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution().repeatedStringMatch("abcd", "cdabcdab"));
    }
}
